<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="cn.egame.common.model.PageData"%>
<%@page import="java.util.*"%>
<%@page import="cn.egame.interfaces.gc.GameInfo"%>   
<%@page import="cn.egame.interfaces.EnumType.GameStatus"%> 
<%@page import="com.egame.manage.biz.server.gc.GameServiceImpl"%> 
<%@page import="cn.egame.interfaces.pu.AppParameter"%>  
<%@page import="cn.egame.common.util.Utils"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/main.css"  />
<script type="text/javascript">
	function listGame(){
		document.getElementById("myform").action = "<%=request.getContextPath() + "/caidan/game/list.do" %>";
		document.getElementById("myform").submit();
	}
	function checkAll(){			
		var gids = document.getElementsByName("gid");
		var allcheck = document.getElementById("allcheck");
		if(allcheck.checked == true){
			for(var i=0;i<gids.length;i++){			
				gids[i].checked = "checked";
			}	
		}else{
			for(var i=0;i<gids.length;i++){			
				gids[i].checked = "";
			}
		}		
	}
	function exportGameData(){
		document.getElementById("myform").action = "<%=request.getContextPath() + "/caidan/game/export.do" %>";
		document.getElementById("myform").submit();
	}
	function formSubmit(){
		document.getElementById("myform").action = "<%=request.getContextPath() + "/caidan/game/list.do" %>";
		document.getElementById("myform").submit();
	}
	function batchOffLine(){
		document.getElementById("url").value="/caidan/game/list.do";
		document.getElementById("updatestatus").value=<%=GameStatus.offLine.value() %>;
		var url = '<%=request.getContextPath() %>'  + '/caidan/game/update/status/list.do' + '?gamestatus=' + <%=GameStatus.business.value() %>;
		document.getElementById("myform").action = url;
		document.getElementById("myform").submit();
	}
	function batchOnLine(){
		document.getElementById("url").value="/caidan/game/list.do";
		document.getElementById("updatestatus").value=<%=GameStatus.business.value() %>;
		var url = '<%=request.getContextPath() %>'  + '/caidan/game/update/status/list.do' + '?gamestatus=' + <%=GameStatus.offLine.value() %>;
		document.getElementById("myform").action = url;
		document.getElementById("myform").submit();
	}	
</script>
<title>游戏上下线</title>
</head>
<body>
<% 
	int status = 0;
	if(request.getAttribute("status")!=null){
		status = (Integer)request.getAttribute("status");
	}	
	String shortName = "";
	if(request.getAttribute("shortName")!= null) {
		shortName = (String)request.getAttribute("shortName");
	}
	
	String gameName = "";
	if(request.getAttribute("gameName")!= null) {
		gameName = (String)request.getAttribute("gameName");
	}
		
%>
<form action="" id="myform">
	<input type=hidden name=url id=url>	
	<input type=hidden name=updatestatus id=updatestatus>
	<div class="matter_box">
		<h3 class="nopoint"><strong>游戏上下线</strong></h3>
		<div class="clearfix nobg mart task_search">
			<p>
				合作方：<input type=text name=shortName value="<%=shortName%>">
				产品名称：<input type=text name=gameName value="<%=gameName%>">	
				<span>产品状态</span>
						<select name="gamestatus">		
							<option value=<%=GameStatus.none.value() %>>全部</option>			
							<option value=<%=GameStatus.auditPassed.value() %> <% if(GameStatus.auditPassed.value() == status){ %> selected="selected" <% } %> ><%=GameStatus.auditPassed.getMessage() %></option>
							<option value=<%=GameStatus.testPassed.value() %> <% if(GameStatus.testPassed.value() == status){ %> selected="selected" <% } %> ><%=GameStatus.testPassed.getMessage() %></option>
							<option value=<%=GameStatus.business.value() %> <% if(GameStatus.business.value() == status){ %> selected="selected" <% } %> ><%=GameStatus.business.getMessage() %></option>
							<option value=<%=GameStatus.published.value() %> <% if(GameStatus.published.value() == status){ %> selected="selected" <% } %>><%=GameStatus.published.getMessage() %></option>
							<option value=<%=GameStatus.offLine.value() %> <% if(GameStatus.offLine.value() == status){ %> selected="selected" <% } %>><%=GameStatus.offLine.getMessage() %></option>
						</select>
					<input type="button" value="查询" class="btn2" onclick="formSubmit()">
					<a href="javascript:;" class="btn2" onclick="exportGameData();">资料导出</a>
					<a href="javascript:;" class="btn2" onclick="batchOnLine();">批量上线</a>
					<a href="javascript:;" class="btn2" onclick="batchOffLine();">批量下线</a>
				</p>
			</div>
			
		<div class="matter_text ">
			<table cellpadding="0" cellspacing="0" class="table2" id="rights_list">
				<tr class="first">
					<th>已审核</th><th>测试通过</th><th>已发布</th><th>商用</th><th>已下线</th><th>总计</th>
				</tr>
				<tr>
					<td><%=GameServiceImpl.getInstance().getGameCount(GameStatus.auditPassed) %> </td>
					<td><%=GameServiceImpl.getInstance().getGameCount(GameStatus.testPassed) %> </td>
					<td><%=GameServiceImpl.getInstance().getGameCount(GameStatus.published) %> </td>
					<td><%=GameServiceImpl.getInstance().getGameCount(GameStatus.business) %> </td>
					<td><%=GameServiceImpl.getInstance().getGameCount(GameStatus.offLine) %> </td>
					<td>
					<% 
						List<Integer> statusList = new ArrayList<Integer>();
						statusList.add(GameStatus.auditPassed.value());
						statusList.add(GameStatus.testPassed.value());
						statusList.add(GameStatus.published.value());
						statusList.add(GameStatus.business.value());
						statusList.add(GameStatus.offLine.value());
					%>
						<%=GameServiceImpl.getInstance().getGameCount(statusList) %>
					</td>
				</tr>
			</table>
		</div>
		<div class="matter_text clearfix nobg mart">
		
			<table cellpadding="0" cellspacing="0" class="table2" id="rights_list">
				<tr class="first">
					<th>
						<input type="checkbox" id="allcheck" onclick="checkAll()">全选
					</th>
					<th>产品编号</th>
					<th>合作方</th>
					<th>产品名称</th>
					<th>产品状态</th>
					<th>更新时间</th>
					<th>操作</th>
				</tr>
					<%
						if(request.getAttribute("pd")!=null){
							PageData pd = (PageData)request.getAttribute("pd");
							if(pd != null && pd.getContent() != null){
								List<GameInfo> list = (List<GameInfo>)pd.getContent();
								for(GameInfo bean:list){
									%>
										<tr>		
											<td>
												<input type="checkbox" name="gid" value="<%=bean.getGId() %>">
											</td>						
											<td>
												<a href="<%=request.getContextPath() + "/caidan/game/show.do?gid=" + bean.getGId() %>"> <%=bean.getGId() %></a>
											</td>
											<td><%=GameServiceImpl.getInstance().getContentProviderInfoById(0, 0L, bean.getCpId()).getShortName()  %></td>
											<td><%=bean.getGameName() %></td>
											<td><%=bean.getGameStatus()==null?"": (bean.getGameStatus()).getMessage() %></td>
											<td>
											<% 
												String time = "";
												if(bean.getUpdateTime() != null && bean.getUpdateTime().getTime()>0){
													time = Utils.toDateString(bean.getUpdateTime(),"yyyy-MM-dd hh:mm:ss");
												}
											%>
												<%=time %>
											</td>
											<td>
											<%
												String updateStatusUrl = request.getContextPath() + "/caidan/game/update/status.do?gid=" + bean.getGId() + "&url=/game/list" + "&gamestatus=" + status + "&updatestatus=";								
												if(bean.getGameStatus()==GameStatus.offLine){
											%>	
												<a href="<%=request.getContextPath() + "/caidan/game/update/status.do?gid=" + bean.getGId() + "&updatestatus=" + GameStatus.business.value() + "&url=/game/list" + "&gamestatus=" + status %>">上线</a>													
											<%
												}else if(bean.getGameStatus()==GameStatus.business){
											%>
												<a href="<%=request.getContextPath() + "/caidan/game/update/status.do?gid=" + bean.getGId() + "&updatestatus=" + GameStatus.offLine.value() + "&url=/game/list" + "&gamestatus=" + status %>">下线</a>							
											<%
												}else if(bean.getGameStatus()==GameStatus.testPassed){
											%>
												<a href="<%=updateStatusUrl + GameStatus.published.value() %>">发布</a>		
											<% } %>
											</td>								
										</tr>
									<%
								}
							}
						}
					%>
				</table>
				<%@ include file="../../page.in"  %>
			</div>
		</div>
	</form>
</body>
</html>